﻿using System;
using System.Collections.Generic;
using System.Text;
using Manager.App_Code;
using Manager.App_Code.IDAL;
using Manager.App_Code.DTO;
using System.Data;

namespace Manager.App_Code.DAL
{
    class TangDAL:StandardConnectDB, ITang
    {
        public List<DTO.TangDTO> GetListTang()
        {
            List<TangDTO> listTang = new List<TangDTO>();
        
            DataTable dt = this.DTExecuteSelect("Select * from Tang");

            foreach (DataRow dr in dt.Rows)
            {
                listTang.Add(ConvertObjectDataRowToTangDTODataRow(dr));
            }

            return listTang;

        }

        public DTO.TangDTO GetTangByID(int Matang)
        {

            TangDTO tangDTO = new TangDTO();

            Dictionary<string, object> paramlist = new Dictionary<string, object>();

            paramlist.Add("@MaTang", Matang);

            DataTable dt = this.DTExecuteSelect("SP_Tang_GetByID", paramlist);

            tangDTO = ConvertObjectDataRowToTangDTODataRow(dt.Rows[0]);

            return tangDTO;
        }

        public bool InsertTang(DTO.TangDTO tang)
        {
            throw new NotImplementedException();
        }

        public bool UpdateTang(DTO.TangDTO tang)
        {
            throw new NotImplementedException();
        }

        public bool DeleteTang(DTO.TangDTO tang)
        {
            throw new NotImplementedException();
        }


        public TangDTO ConvertObjectDataRowToTangDTODataRow(System.Data.DataRow dr)
        {
            if (dr != null)
            {
                TangDTO tang = new TangDTO();
                tang.MaTang = int.Parse(dr["MaTang"].ToString());
                tang.TenTang = dr["TenTang"].ToString();
                tang.ViTri = int.Parse(dr["ViTri"].ToString());

                return tang;

            }
            else
                return null;
            

        }
    }
}
